<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>新增客户信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/admin/css/input1.css"/>
<script src="${pageContext.request.contextPath }/admin/js/reg.js"></script>
<c:choose>
	<c:when test="${stationid eq null }"><script>var sid=-1;</script></c:when>
	<c:otherwise><script>var sid=${stationid};</script></c:otherwise>
</c:choose>
<script>
	$(function(){
//		$.messager.alert('系统消息','子栏目删除成功！');
		$('#fb').filebox({ 
		 	buttonText: '请选择文件', 
		 	buttonAlign: 'right',
		 	editable:false 
		});

		// 地推人员下拉列表
		$('#salesman').combobox({
			valueField:'userid',
			textField:'username',
			url:'${pageContext.request.contextPath }/admin/user/listUserByRole/4'
		});
		$('#salesman').combobox("setValue",-1);
				
		// 站点下拉列表
		$('#stationId').combobox({
			valueField:'station_id',
			textField:'station_name',
			url:'${pageContext.request.contextPath }/admin/station/findStationByKind/1'
		});
		$('#stationId').combobox("setValue",sid);
		
		// 提货仓列表
		$('#takeStationId').combobox({
			valueField:'station_id',
			textField:'station_name',
			url:'${pageContext.request.contextPath }/admin/station/findStationByKind/1'
		});
		$('#takeStationId').combobox("setValue",sid);
		$("a[name='qsave']").linkbutton({text:'保存客户信息',plain:true,iconCls:'icon-ok'});
		
	});
	
	function doSub(){
		var cname=$('#cname').val();
		if($.trim(cname)==''){
			$.messager.alert('系统消息','<span style="color:red;">客户姓名必须输入！</span>');
			$('#cname').textbox('textbox').focus(); 
    		return;
		}
		var mobile=$('#mobile').val();
		if(!isValidMobilePhone(mobile)){
			$.messager.alert('系统消息','<span style="color:red;">电话号码必须输入，且必须是11位数字！</span>'); 
    		return;
		}
		var salesman=$('#salesman').combobox("getValue");
		if(salesman==-1){
			$.messager.alert('系统消息','<span style="color:red;">地推人员必须选择<br/>[备注：请直接选择地推人员]</span>');
			return;
		}
		var stationId=$('#stationId').combobox("getValue");
		if(stationId==-1){
			$.messager.alert('系统消息','<span style="color:red;">客户所属站点必须选择<br/>[备注：目前请将所属站点和提货仓保持一致]</span>');
			return;
		}
		var takeStationId=$('#takeStationId').combobox("getValue");
		if(takeStationId==-1){
			$.messager.alert('系统消息','<span style="color:red;">客户所属提货仓必须选择<br/>[备注：目前请将所属站点和提货仓保持一致]</span>');
			return;
		}
		if(stationId!=takeStationId){
			$.messager.alert('系统消息','<span style="color:red;">请将客户所属提货仓和客户所属站点选择一样的内容！</span>');
			return;
		}
	//	$('#addCustomer').submit();
		validUser();
	}
	
	// 验证电话号码是否存在(data-options="onChange:function(){validUser()}"/>)
	function validUser(){		
		var mobile=$('#mobile').val();
		$.post("${pageContext.request.contextPath}/admin/customer/findExistsCustomer",{mobile:mobile},
			function(data){
				if(data=="1"){
					$.messager.alert('系统消息','<span style=\"color:red;\">该客户信息已经存在，请核实后再试！</span>');	 
				}else{
					$('#addCustomer').submit();	
		//			$.messager.alert('系统消息','<span style=\"color:red;\">提交！</span>');	
				}						
			},"text");
	}
</script>
</head>

<body>
<form method="post" id="addCustomer" action="${pageContext.request.contextPath }/admin/customer/addCustomer" enctype="multipart/form-data">
<div class="i-container" style="width:1000px;">
	<div class="i-common i-title">添加客户信息
		<span style="color:red; margin-left:30px;">${addMsg }</span>
		<div class="i-btn"><a id="btn" href="javascript:doSub()" name="qsave"></a></div><div style=" clear:both;"></div>
	</div>
    <div class="i-common i-cnt-left">客户姓名：</div><div class="i-common i-cnt-right">
    	<input name="customer.CUST_NAME" id="cname" class="easyui-textbox" style="width:210px;height:26px"/>
    </div>
    <div class="i-common i-cnt-middle">客户性别：</div>
    <div class="i-common i-cnt-right">
    	<input type="radio" name="customer.CUST_SEX" value='0' checked="checked"/>男&nbsp;&nbsp;&nbsp;
    	<input type="radio" name="customer.CUST_SEX" value='1' />女
    </div>
    <div class="i-common i-cnt-middle">手机号码：</div>
    <div class="i-common i-cnt-right">
    	<input name="customer.MOBILE" id="mobile" class="easyui-textbox" style="width:210px;height:26px" />
    </div>
    <div style="clear:both;"></div>
    <div class="i-common i-cnt-left">身份证号：</div>
    <div class="i-common i-cnt-right">
    	<input name="customer.CUST_IDENTITY" id="identity" class="easyui-textbox" style="width:210px;height:26px"/>
    </div>
    <div class="i-common i-cnt-middle">身份证图片：</div>
    <div class="i-common i-cnt-right">
    	<input id="fb" name="img" data-options="prompt:'请选择身份证图片...'" style="width:210px;height:26px" accept="image/gif,image/jpeg,image/png"/>
    </div>
    <div class="i-common i-cnt-middle">地推人员：</div>
    <div class="i-common i-cnt-right">
    	<input name="customer.SALESMAN" id="salesman" class="easyui-textbox" style="width:210px;height:26px"/>
    </div>
    <div style="clear:both;"></div> 
    <div class="i-common i-cnt-left">所属站点：</div>
    <div class="i-common i-cnt-right">
		<input name="customer.STATION_ID" id="stationId" class="easyui-textbox" style="width:210px;height:26px"/>
	</div>
    <div class="i-common i-cnt-middle">所属提货仓：</div>
    <div class="i-common i-cnt-right">
    	<input name="customer.TAKE_STATION_ID" id="takeStationId" class="easyui-textbox" style="width:210px;height:26px"/>
    </div>
    <div class="i-common i-cnt-middle">是否有效：</div>
    <div class="i-common i-cnt-right">
    	<input type="radio" name="customer.IS_VALID" value='1' checked="checked"/>正常使用&nbsp;&nbsp;&nbsp;
    	<input type="radio" name="customer.IS_VALID" value='0'/>禁止使用
    </div>
    <div style="clear:both;"></div>
    
    <div class="i-common i-cnt-left">客户摊位：</div>
    <div class="i-common i-cnt-right">
		<input name="customer.POSITION" id="stationId" class="easyui-textbox" style="width:210px;height:26px"/>
	</div>
    <div class="i-common i-cnt-middle">市场地址：</div>
    <div class="i-common i-cnt-right">
    	<input name="customer.MARKET_ADDRESS" id="stationId" class="easyui-textbox" style="width:210px;height:26px" value="湖北武汉"/>
    </div>
    <div class="i-common i-cnt-middle">&nbsp;</div>
    <div class="i-common i-cnt-right">
    	&nbsp;
    </div>
    <div style="clear:both;"></div>
</div>

</form>
</body>
</html>
